﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Data.SqlClient;

public class tbReplyDB
{
    #region[tbReply_Add]
    public static bool tbReply_Add(tbReplyDATA _tbReplyDATA)
    {
        bool check = false;
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbReply_Add", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@prID", _tbReplyDATA.prID));
                dbCmd.Parameters.Add(new SqlParameter("@reName", _tbReplyDATA.reName));
                dbCmd.Parameters.Add(new SqlParameter("@reContent", _tbReplyDATA.reContent));
                dbCmd.Parameters.Add(new SqlParameter("@peFiles", _tbReplyDATA.peFiles));
                dbCmd.Parameters.Add(new SqlParameter("@uSend", _tbReplyDATA.uSend));
                dbCmd.Parameters.Add(new SqlParameter("@uRec", _tbReplyDATA.uRec));
                dbCmd.Parameters.Add(new SqlParameter("@reType", _tbReplyDATA.reType));
                dbCmd.ExecuteNonQuery();
                dbConn.Close();
                check = true;
            }
        }
        return check;
    }
    #endregion
    #region[tbReply_GetByIDprID]
    public static List<tbReplyDATA> tbReply_GetByIDprID(string prID)
    {
        List<tbReplyDATA> list = new List<tbReplyDATA>();
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbReply_GetByIDprID", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@prID", prID));
                using (SqlDataReader reader = dbCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tbReplyDATA objtbReplyDATA = new tbReplyDATA(
                        reader["reID"].ToString(),
                        reader["prID"].ToString(),
                        reader["reName"].ToString(),
                        reader["reContent"].ToString(),
                        reader["peFiles"].ToString(),
                        reader["peSendDate"].ToString(),
                        reader["uSend"].ToString(),
                        reader["uRec"].ToString(),
                        reader["reType"].ToString());
                        list.Add(objtbReplyDATA);
                    }
                }
                dbConn.Close();
            }
        }
        return list;
    }
    #endregion
    #region[tbReply_GetBy_prID_uRec]
    public static List<tbReplyDATA> tbReply_GetBy_prID_uRec(string uRec, string prID)
    {
        List<tbReplyDATA> list = new List<tbReplyDATA>();
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbReply_GetBy_prID_uRec", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@uRec", uRec));
                dbCmd.Parameters.Add(new SqlParameter("@prID", prID));
                using (SqlDataReader reader = dbCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tbReplyDATA objtbReplyDATA = new tbReplyDATA(
                        reader["reID"].ToString(),
                        reader["prID"].ToString(),
                        reader["reName"].ToString(),
                        reader["reContent"].ToString(),
                        reader["peFiles"].ToString(),
                        reader["peSendDate"].ToString(),
                        reader["uSend"].ToString(),
                        reader["uRec"].ToString(),
                        reader["reType"].ToString());
                        list.Add(objtbReplyDATA);
                    }
                }
                dbConn.Close();
            }
        }
        return list;
    }
    #endregion
}
